package com.xs.arraylist;

import java.util.ArrayList;

public class ArrayList03 {
    public static void main(String[] args) {
        ArrayList<String> ary=new ArrayList<>();
        ary.add("java");
        ary.add("one");
        ary.add("two");
        ary.add("fack");

        //1.public E get(int index);获取某个索引位置的元素
        String ys= ary.get(1);
        System.out.println(ys);
        System.out.println("-----------------------");

        //2.public int size();获取集合的大小
        int ys1=ary.size();
        System.out.println("共有"+ys1+"个元素");
         System.out.println("-----------------------");

        //3.集合遍历
        for (int i = 0; i < ary.size(); i++) {
            System.out.println( ary.get(i));
        }
         System.out.println("-----------------------");

        //4.public E remove(int index);删除某个索引位置的元素
        String sy2=ary.remove(1);
        System.out.println(ary);
         System.out.println("-----------------------");

        //5.public boolean remove(Object o);直接删除元素,删除成功显示ture，失败返回flase
        //当存在多个相同元素时只会删除第一次出现的元素
        boolean sy3=ary.remove("fack");
        System.out.println(ary);
         System.out.println("-----------------------");

        //6.public E set(int index,E element);修改某个索引位置处的元素
        String sy4=ary.set(0,"我爱你");
        System.out.println(ary);

    }
}
